﻿/********************************************************************************
** @ Date:2024/02/20
** @ Author: WeiXiaoYu
** @ Description: WebSocket服务线程类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CWebSocketSrvThread_H
#define CWebSocketSrvThread_H
#include <QAbstractSocket>
#include <QWebSocketServer>
#include <QWebSocket>
#include <QMutex>
#include <QImage>
#include "QThreadBase.h"
#include "CWebSocketClient.h"
#include <qeventloop.h>
class CWebSocketSrvThread :
    public QThreadBase
{
    Q_OBJECT
public:
    CWebSocketSrvThread();
    ~CWebSocketSrvThread();

	void clearClient();//清除客户端

	/*全局静态 设备关注*/


private slots:
	virtual void slotWorkProc();//工作线程
    void initSrv();//初始化服务
	void getNewConnection();//当有新连接过来时处理
	void onError(QAbstractSocket::SocketError error);
	void disConnect();//有客户端断开连接
	void ReceivedMsg(const QString &message);//有客户端发来消息

private:
    bool isValidIPAddress(const QString &ipAddress);//判断是否是有效的ip地址

private:
	QWebSocketServer *m_pWebSocketServer = nullptr;
	bool m_bIsInit;
	QMutex m_mxClient;
	QVector<CWebSocketClient*> m_vecClient;
};

#endif // CWebSocketSrvThread_H
